package com.zyh.service.impl;

import com.zyh.entity.BorrowBookVo;
import com.zyh.entity.MenuChildren;
import com.zyh.entity.Message;
import com.zyh.entity.MessagesChildren;
import com.zyh.mapper.Emailmapper;
import com.zyh.service.EmailService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmailServiceImpl implements EmailService {
    @Autowired
    Emailmapper emailmapper;

    @Value("${spring.mail.username}")
    private String username;
    @Autowired
    JavaMailSenderImpl mailSender;
    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public void sendEmail(String toEmail, String title, String content) {
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setFrom(username);
        simpleMailMessage.setTo(toEmail);
        simpleMailMessage.setSubject(title);
        simpleMailMessage.setText(content);
        mailSender.send(simpleMailMessage);
        logger.info("邮件发送成功！");
//        emailmapper.sendEmail(toEmail, title, content);

    }

    @Override
    public BorrowBookVo selectEmailByid(BorrowBookVo borrowBookVo) {
        return emailmapper.selectEmailByid(borrowBookVo);
    }

    @Override
    public int insertmessage(MessagesChildren message) {
        return emailmapper.insertmessage(message);
    }
}
